<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>






<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  

  

  

  

  

  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="物联网 (IoT)," />





  <link rel="alternate" href="/atom.xml" title="万秦龙 Hyman Wan" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="2017年8月23日星期三 ﻿发布人：IoT 开发技术推广工程师 Wayne Piekarski  我们宣布推出 Android Things 的 Developer Preview 5 (DP5) 版本，该版本包含基于未来 Android O 版本的重要变更。Android Things 是 Google 推出的平台，旨在帮助 Android 开发者打造物联网 (IoT) 设备，并从原型开发无缝">
<meta name="keywords" content="物联网 (IoT)">
<meta property="og:type" content="article">
<meta property="og:title" content="《物联网 (IoT)  | Android Things Developer Preview 5 》">
<meta property="og:url" content="http://wanqinlong.com/2017/09/15/03Google_01IoT_02AndroidThingsP5/index.html">
<meta property="og:site_name" content="万秦龙 Hyman Wan">
<meta property="og:description" content="2017年8月23日星期三 ﻿发布人：IoT 开发技术推广工程师 Wayne Piekarski  我们宣布推出 Android Things 的 Developer Preview 5 (DP5) 版本，该版本包含基于未来 Android O 版本的重要变更。Android Things 是 Google 推出的平台，旨在帮助 Android 开发者打造物联网 (IoT) 设备，并从原型开发无缝">
<meta property="og:image" content="https://i.imgur.com/EalbvxB.png">
<meta property="og:image" content="https://i.imgur.com/zeJq8Lv.png">
<meta property="og:image" content="https://i.imgur.com/JeDxth1.png">
<meta property="og:updated_time" content="2017-11-08T00:28:23.039Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="《物联网 (IoT)  | Android Things Developer Preview 5 》">
<meta name="twitter:description" content="2017年8月23日星期三 ﻿发布人：IoT 开发技术推广工程师 Wayne Piekarski  我们宣布推出 Android Things 的 Developer Preview 5 (DP5) 版本，该版本包含基于未来 Android O 版本的重要变更。Android Things 是 Google 推出的平台，旨在帮助 Android 开发者打造物联网 (IoT) 设备，并从原型开发无缝">
<meta name="twitter:image" content="https://i.imgur.com/EalbvxB.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://wanqinlong.com/2017/09/15/03Google_01IoT_02AndroidThingsP5/"/>





  <title>《物联网 (IoT)  | Android Things Developer Preview 5 》 | 万秦龙 Hyman Wan</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  















  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">万秦龙 Hyman Wan</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Android Developer | Learning ios</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-resource">
          <a href="/resource" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-code"></i> <br />
            
            文档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-link">
          <a href="/link" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-link"></i> <br />
            
            连接
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://wanqinlong.com/2017/09/15/03Google_01IoT_02AndroidThingsP5/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="万秦龙">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="万秦龙 Hyman Wan">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">《物联网 (IoT)  | Android Things Developer Preview 5 》</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-15T13:12:38+00:00">
                2017-09-15
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Google/" itemprop="url" rel="index">
                    <span itemprop="name">Google</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Google/物联网-IoT/" itemprop="url" rel="index">
                    <span itemprop="name">物联网 (IoT)</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a class="cloud-tie-join-count" href="/2017/09/15/03Google_01IoT_02AndroidThingsP5/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count join-count" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>2017年8月23日星期三</p>
<p>﻿发布人：IoT 开发技术推广工程师 <a href="https://google.com/+WaynePiekarski" target="_blank" rel="external">Wayne Piekarski</a> </p>
<p>我们宣布推出 <a href="https://developer.android.google.cn/things/index.html" target="_blank" rel="external">Android Things</a> 的 Developer Preview 5 (DP5) 版本，该版本包含基于未来 Android O 版本的重要变更。Android Things 是 Google 推出的平台，旨在帮助 Android 开发者打造物联网 (IoT) 设备，并从原型开发无缝扩展到量产。</p>
<h1 id="Android-O"><a href="#Android-O" class="headerlink" title="Android O"></a>Android O</h1><p>对于手机和平板电脑，Android O 目前正处于 <a href="https://android-developers.googleblog.com/2017/07/developer-preview-4-now-available.html" target="_blank" rel="external">Developer Preview</a> 阶段，而 DP5 则恰恰基于这一即将发布的版本（之前的版本基于 Android N）。这意味着，您未来的 Android Things 应用应针对 API 26，方可在该平台上正确使用我们的支持库。</p>
<h1 id="硬件变更"><a href="#硬件变更" class="headerlink" title="硬件变更"></a>硬件变更</h1><p>现在，DP5 新增了对全新 <a href="https://developer.android.google.cn/things/hardware/imx6ul.html" target="_blank" rel="external">NXP SprIoT i.MX6UL</a> 设计的支持，在我们的开发者套件<a href="https://developer.android.google.cn/things/hardware/developer-kits.html" target="_blank" rel="external">文档</a>中列出了这一变更。随着 Intel 停止 <a href="https://software.intel.com/en-us/iot/hardware/edison" target="_blank" rel="external">Edison</a> 和 <a href="https://software.intel.com/en-us/iot/hardware/joule" target="_blank" rel="external">Joule</a> 硬件设计，这些平台即将转入旧设备支持阶段。它们不会继续收到最新的平台更新，但开发者仍可从 Android Things 管理中心继续获取 DP4.1 系统映像。 </p>
<p>Android Things 的一个重要目标是：帮助开发者从原型开发无缝扩展到量产。当我们结束 Developer Preview 时，我们将会在以仅原型开发为目标的硬件平台和可扩展到量产的硬件参考设计之间进行差异化。可量产的硬件将满足 Google 的安全要求并享有硅半导体制造商的长期支持。稍后，我们还会分享更多内容。</p>
<ul>
<li>NXP SprIoT i.MX6UL</li>
</ul>
<p><img src="https://i.imgur.com/EalbvxB.png" alt=""></p>
<a id="more"></a>
<ul>
<li>Edison</li>
</ul>
<p><img src="https://i.imgur.com/zeJq8Lv.png" alt=""></p>
<ul>
<li>Joule</li>
</ul>
<p><img src="https://i.imgur.com/JeDxth1.png" alt=""></p>
<h1 id="改进"><a href="#改进" class="headerlink" title="改进"></a>改进</h1><p>随着我们开始迁移到 Android O 代码库，Android 中提供了一些新的 API 功能，还有一些专门针对 Android Things 的功能。对于使用 UserDriver API 的开发者来说，您将需要在 AndroidManifest.xml 中添加新的权限。<a href="https://developers.android.com/things/sdk/drivers/index.html" target="_blank" rel="external">文档</a>中包含有关每种类型的驱动程序所需的权限详情。DP5 现在还支持在 Raspberry Pi 3 平台上运行 OpenGL ES 2.0 和 WebView，这是开发者社区呼声甚高的一项功能。我们还针对 Raspberry Pi 3 实现了<a href="https://developer.android.google.cn/things/hardware/raspberrypi-mode-matrix.html" target="_blank" rel="external">动态引脚多路复用</a>功能，引脚在运行时根据所要使用的功能进行配置。</p>
<h1 id="Android-Studio"><a href="#Android-Studio" class="headerlink" title="Android Studio"></a>Android Studio</h1><p>现在，可直接在 Android Studio 中获取 Android Things 示例，以进行浏览和导入。现在，只需进入 File、New、Import Samples 并搜索 Things，即可查看提供的所有示例。我们提供丰富多样的示例，展示了如何与按钮、传感器、LED 和显示屏交互以及如何实现 Google 智能助理和 TensorFlow。</p>
<h1 id="Android-Things-管理中心"><a href="#Android-Things-管理中心" class="headerlink" title="Android Things 管理中心"></a>Android Things 管理中心</h1><p>我们最近<a href="https://android-developers.googleblog.com/2017/06/android-things-console-developer-preview.html" target="_blank" rel="external">启动</a>了 <a href="https://partner.android.com/things/console" target="_blank" rel="external">Android Things 管理中心</a>，其能够支持对 Android Things 设备的无线更新 (OTA)。我们最近对该管理中心做出了大量用户体验方面的改进，以改善易用性和功能。DP5 现已可在 Android Things 管理中心内部获取，但未经您的干预，DP5 更新不会自动推送到设备。您需要针对 DP5 更新您的应用，然后创建一个新更新并通过管理中心自行推送更新。</p>
<h1 id="反馈"><a href="#反馈" class="headerlink" title="反馈"></a>反馈</h1><p>在将 Android Things 更新到 Android O 时，我们对该平台做出了一些重要变更。请提<a href="https://code.google.com/p/android/issues/entry?template=Android%20Things%20bug%20report" target="_blank" rel="external">交错误报告</a>和<a href="https://code.google.com/p/android/issues/entry?template=Android%20Things%20feature%20request" target="_blank" rel="external">功能请求</a>，继续向我们发送您的反馈，并欢迎在 <a href="https://stackoverflow.com/questions/tagged/android-things" target="_blank" rel="external">Stack Overflow</a> 上提出任何问题。要开始使用 DP5，请使用 <a href="https://partner.android.com/things/console" target="_blank" rel="external">Android Things 管理中心</a>下载系统映像并更新现有设备。<a href="https://developer.android.google.cn/things/preview/releases.html" target="_blank" rel="external">版本说明</a>中提供了有关这些变更的更多信息。您也可以在 Google+ 上加入 Google 的 IoT 开发者社群，这是一个非常有用的资源，在这里，您可以了解最新消息并讨论想法。此外，我们还建立了新的 <a href="https://www.hackster.io/google" target="_blank" rel="external">hackster.io 社群</a>，在这里，每个人都可以分享他们创建的精彩项目！ </p>
<hr>
<p><a href="http://developers.googleblog.cn/2017/08/android-things-developer-preview-5.html" target="_blank" rel="external">原文</a></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div></div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="/path/to/wechat-reward-image" alt="万秦龙 WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="/path/to/alipay-reward-image" alt="万秦龙 Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/物联网-IoT/" rel="tag"># 物联网 (IoT)</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/12/00阅读.中国_01人是万物尺度/" rel="next" title="《阅读.中国 | 人是万物尺度》">
                <i class="fa fa-chevron-left"></i> 《阅读.中国 | 人是万物尺度》
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/20/00阅读.中国_02商业分析01：只爱研究技术不爱做产品/" rel="prev" title="《商业探索，人物读心 |《中国开发者研究技术的热情大于做产品的热情》》">
                《商业探索，人物读心 |《中国开发者研究技术的热情大于做产品的热情》》 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
  <a class="jiathis_button_tsina"></a>
  <a class="jiathis_button_tqq"></a>
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_cqq"></a>
  <a class="jiathis_button_douban"></a>
  <a class="jiathis_button_renren"></a>
  <a class="jiathis_button_qzone"></a>
  <a class="jiathis_button_kaixin001"></a>
  <a class="jiathis_button_copy"></a>
  <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
  var jiathis_config={
    hideMore:false
  }
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="万秦龙" />
          <p class="site-author-name" itemprop="name">万秦龙</p>
           
              <p class="site-description motion-element" itemprop="description">货币构建幸福，商业温暖人心</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">14</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">12</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Android-O"><span class="nav-number">1.</span> <span class="nav-text">Android O</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#硬件变更"><span class="nav-number">2.</span> <span class="nav-text">硬件变更</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#改进"><span class="nav-number">3.</span> <span class="nav-text">改进</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Android-Studio"><span class="nav-number">4.</span> <span class="nav-text">Android Studio</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Android-Things-管理中心"><span class="nav-number">5.</span> <span class="nav-text">Android Things 管理中心</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#反馈"><span class="nav-number">6.</span> <span class="nav-text">反馈</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">万秦龙</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  
    
    <script>
      var cloudTieConfig = {
        url: document.location.href, 
        sourceId: "",
        productKey: "77ab315ba35e4a9fba801ece5562c92d",
        target: "cloud-tie-wrapper"
      };
    </script>
    <script src="https://img1.ws.126.net/f2e/tie/yun/sdk/loader.js"></script>
  










  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (search_path.endsWith("json")) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
  


  

  

</body>
</html>
